package org.dbwebx.flex.control.renderer
{

	import mx.containers.HBox;
	import mx.controls.Label;
	import mx.core.ScrollPolicy;
	import org.dbwebx.domain.Bundle;
	import org.dbwebx.domain.SourceNode;

	public class SourceNodeGridRenderer extends HBox
	{

		public function SourceNodeGridRenderer()
		{
			super();
			horizontalScrollPolicy=ScrollPolicy.OFF;
			percentWidth=100;
		}

		/**
		 * The label.
		 * @default
		 */
		protected var labelField:Label;

		private var _maxLabelWidth:uint;
		private var _maxLabelWidthChanged:Boolean;

		override public function set data(value:Object):void
		{
			super.data=value;
			invalidateSize();
			invalidateDisplayList();
		}

		override protected function commitProperties():void
		{
			super.commitProperties();
			if (data && data is Bundle && Bundle(data).sourceNode)
			{
				var sourceNode:SourceNode=Bundle(data).sourceNode;
				labelField.text=sourceNode.name;
			}
			//check whether max width was defined
			if (_maxLabelWidthChanged)
			{
				labelField.maxWidth=maxLabelWidth;
				_maxLabelWidthChanged=false;
			}
		}

		override protected function createChildren():void
		{
			super.createChildren();
			labelField=new Label();
			addChild(labelField);
		}

		protected function get maxLabelWidth():uint
		{
			return _maxLabelWidth;
		}

		protected function set maxLabelWidth(value:uint):void
		{
			_maxLabelWidth=value;
			_maxLabelWidthChanged=true;
			invalidateProperties();
		}

	}
}